const cos = require('../../../oss/init')
const constant =require('../../../constant/index')
const BucketFn = async(path='')=>{
    return await cos.getBucket({
        Bucket:constant.BUCKET,
        Region:constant.REGION,
        Prefix:path,
        Delimiter:'/'
    })
}

//列出存储桶目录
const adminGetCosCatalogue = async (req,res)=>{
    const result =  await  BucketFn()
     const ParentRoutesName = result.CommonPrefixes.map((item) => `${item.Prefix.replace('/','')}`);
     const ParentRoutesPath = result.CommonPrefixes.map(item=>`/${item.Prefix.replace('/','')}`)
    if(result){
       const nextFolder=   await BucketFn(result.CommonPrefixes[0].Prefix)
       if(nextFolder){
        const ChildRoutesPath =nextFolder.CommonPrefixes.map(item=>`/${item.Prefix}index.vue`)
        const ChildRoutesName = nextFolder.CommonPrefixes.map((item)=>`${item.Prefix.split('/')[1]}`)
        res.send({
            ParentRoutesName,
            ParentRoutesPath,
            ChildRoutesPath,
            ChildRoutesName
        })
       }
    }
}
module.exports =adminGetCosCatalogue